/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
func getMinimumDifference(root *TreeNode) int {
    if root == nil {
        return 0
    }

    // 记录上一个节点
    var preNode *TreeNode
    // 记录最小值
    min := math.MaxInt64

    var traverse func (node *TreeNode) 
    traverse =  func (node *TreeNode) {
        if node == nil {
            return
        }
        traverse(node.Left)
        if preNode != nil && node.Val - preNode.Val < min{
            min = node.Val - preNode.Val
        } 
        preNode = node
        traverse(node.Right)
    }
    traverse(root)
    return min
}